package com.bawei.module_home.discovery.adapter.provider

import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.StaggeredGridLayoutManager
import com.bawei.library_widget.CustomItemDecoration
import com.bawei.library_widget.CustomItemHorizontalDecoration
import com.bawei.module_home.R
import com.bawei.module_home.discovery.adapter.CategoryItemAdapter
import com.bawei.module_home.discovery.entity.DiscoveryEntity
import com.blankj.utilcode.util.SizeUtils
import com.chad.library.adapter.base.provider.BaseItemProvider
import com.chad.library.adapter.base.viewholder.BaseViewHolder

/**
 * @Author : yaotianxue
 * @Time : On 2023/5/29 19:53
 * @Description : CategoryCardProvider
 */
class CategoryCardProvider(override val itemViewType: Int, override val layoutId: Int) :BaseItemProvider<DiscoveryEntity.Item>(){
    override fun convert(helper: BaseViewHolder, item: DiscoveryEntity.Item) {
        var tvTitle = helper.getView<TextView>(R.id.tv_title)
        var tvActionTitle = helper.getView<TextView>(R.id.tv_action_title)
        tvTitle.text = item.data.header.title.toString()
        tvActionTitle.text = item.data.header.rightText.toString()
        //加载列表
        var rv = helper.getView<RecyclerView>(R.id.rv_category_view)
        var categoryItemAdapter = CategoryItemAdapter(R.layout.home_item_category_item_card_view,item.data.itemList as MutableList )
        rv.adapter = categoryItemAdapter
        rv.layoutManager =  StaggeredGridLayoutManager(2,StaggeredGridLayoutManager.HORIZONTAL)
        if(rv.itemDecorationCount == 0){
            rv.addItemDecoration(CustomItemHorizontalDecoration(2,context.resources.getDimension(com.bawei.library_common.R.dimen.dp_2).toInt()))
        }


    }
}